package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.daimajia.swipe.SwipeLayout;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.SignSummaryOriginal;
import com.isunland.managesystem.utils.MyDateUtil;
import java.util.List;

/**
 * 创建者: HuXiaoDan
 * 日期: 2016/12/14 17:19
 */
//public class SignSummaryListAdapter extends BaseListAdapter<SignSummaryOriginal.SignSummaryContent> {
//    public SignSummaryListAdapter(Context context, List<SignSummaryOriginal.SignSummaryContent> objects) {
//        super(context, objects);
//    }
//
//    @Override
//    public void bindData(int position, ViewHolder vh, SignSummaryOriginal.SignSummaryContent item) {
//        vh.mTitleOneTv.setText(R.string.rsignInTime);
//        vh.mTitleTwoTv.setText(R.string.rsignOutTime);
//        vh.mTitleThreeTv.setText(R.string.attendanceStatus);//考勤状态
//        vh.mTitleFourTv.setText(R.string.attendancePerson);//考勤人
//        vh.mContentOneTv.setText(item.getPsignInTime());
//        vh.mContentTwoTv.setText(item.getPsignOutTime());
//        vh.mContentThreeTv.setText(item.getAttendStatusName());
//        vh.mContentThreeTv.setTextColor(getContext().getResources().getColor(R.color.blue_textColor));
//        vh.mContentFourTv.setText(item.getStaffName());
//        //工作日状态
//        vh.mLlPlanStatus.setVisibility(View.VISIBLE);
//        if ("T".equalsIgnoreCase(item.getIfWorkDay())) {
//            vh.mTvPlanStatus.setText(R.string.workDay);
//            vh.mTvPlanStatus.setTextColor(getContext().getResources().getColor(R.color.blue_bg));
//        } else if ("F".equalsIgnoreCase(item.getIfWorkDay())) {
//            vh.mTvPlanStatus.setText(R.string.noWorkDay);
//            vh.mTvPlanStatus.setTextColor(getContext().getResources().getColor(R.color.red));
//        }
//
//    }
//
//    @Override
//    public boolean isEmpty() {
//        return false;
//    }
//}

public class SignSummaryListAdapter extends ArrayAdapter<SignSummaryOriginal.SignSummaryContent> {
  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-12-15 16:38:59 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final SwipeLayout rootView;
    public final TextView tvNameAttendanceSummary;
    public final TextView tvDeptNameAttendanceSummary;
    public final TextView tvTimeAttendanceSummary;
    public final TextView tvSinInAttendanceSummary;
    public final TextView tvSinOutAttendanceSummary;
    public final ImageView mLLSwipe;
    public final ImageView mIvPhoto;
    public TextView tvPersonAttendanceSummary;
    public final TextView tvAttendGroupAttendanceSummary;
    public final TextView tvAttendStatusAttendanceSummary;

    private ViewHolder(SwipeLayout rootView, TextView tvNameAttendanceSummary,
        TextView tvDeptNameAttendanceSummary, TextView tvTimeAttendanceSummary,
        TextView tvSinInAttendanceSummary, TextView tvSinOutAttendanceSummary, ImageView mLLSwipe,
        TextView tvPersonAttendanceSummary, ImageView mIvPhoto,
        TextView tvAttendGroupAttendanceSummary, TextView tvAttendStatusAttendanceSummary) {
      this.rootView = rootView;
      this.tvNameAttendanceSummary = tvNameAttendanceSummary;
      this.tvDeptNameAttendanceSummary = tvDeptNameAttendanceSummary;
      this.tvTimeAttendanceSummary = tvTimeAttendanceSummary;
      this.tvSinInAttendanceSummary = tvSinInAttendanceSummary;
      this.tvSinOutAttendanceSummary = tvSinOutAttendanceSummary;
      this.mLLSwipe = mLLSwipe;
      this.tvPersonAttendanceSummary = tvPersonAttendanceSummary;
      this.mIvPhoto = mIvPhoto;
      this.tvAttendGroupAttendanceSummary = tvAttendGroupAttendanceSummary;
      this.tvAttendStatusAttendanceSummary = tvAttendStatusAttendanceSummary;
    }

    public static ViewHolder create(SwipeLayout rootView) {
      TextView tvNameAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_name_attendanceSummary);
      TextView tvDeptNameAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_deptName_attendanceSummary);
      TextView tvTimeAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_time_attendanceSummary);
      TextView tvSinInAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_sinIn_attendanceSummary);
      TextView tvSinOutAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_sinOut_attendanceSummary);
      ImageView mLLSwipe = (ImageView) rootView.findViewById(R.id.ll_swipe);
      TextView tvPersonAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_person_attendanceSummary);
      TextView tvAttendGroupAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_AttendGroup_attendanceSummary);
      TextView tvAttendStatusAttendanceSummary =
          (TextView) rootView.findViewById(R.id.tv_attendStatus_attendanceSummary);
      ImageView mIvPhoto = (ImageView) rootView.findViewById(R.id.iv_photo);
      return new ViewHolder(rootView, tvNameAttendanceSummary, tvDeptNameAttendanceSummary,
          tvTimeAttendanceSummary, tvSinInAttendanceSummary, tvSinOutAttendanceSummary, mLLSwipe,
          tvPersonAttendanceSummary, mIvPhoto, tvAttendGroupAttendanceSummary,
          tvAttendStatusAttendanceSummary);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_attendance_summary, parent, false);
      vh = ViewHolder.create((SwipeLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }
    vh.mLLSwipe.setVisibility(View.GONE);//SwipeLayout不显示侧滑图片
    SignSummaryOriginal.SignSummaryContent item = getItem(position);

    // 时间
    vh.tvTimeAttendanceSummary.setText(
        String.format("%s月%s日  星期%s", item.getSignInMonth(), item.getSignInDate(),
            item.getWeekDay()));//日期
    vh.tvPersonAttendanceSummary.setText(item.getStaffName());//考勤人
    //考勤人员部门
    vh.tvDeptNameAttendanceSummary.setText(item.getDeptName());
    //考勤状态
    vh.tvAttendStatusAttendanceSummary.setText(item.getAttendStatusName());
    //是否是工作日
    if ("T".equalsIgnoreCase(item.getIfWorkDay())) {
      vh.tvSinOutAttendanceSummary.setTextColor(
          getContext().getResources().getColor(R.color.blue_textColor));
    } else if ("F".equalsIgnoreCase(item.getIfWorkDay())) {
      vh.tvSinOutAttendanceSummary.setTextColor(getContext().getResources().getColor(R.color.red));
    }
    //考勤分组
    if (!TextUtils.isEmpty(item.getAttendGroupName())) {
      vh.tvNameAttendanceSummary.setVisibility(View.VISIBLE);
      vh.tvAttendGroupAttendanceSummary.setText(item.getAttendGroupName());
    } else {
      vh.tvAttendGroupAttendanceSummary.setVisibility(View.GONE);
    }

    String inTime = "";
    String outTime = "";
    if (!TextUtils.isEmpty(item.getPsignInTime())) {
      inTime =
          MyDateUtil.parseTimeToString(MyDateUtil.stringToDate(item.getPsignInTime()), "kk:mm");
    }
    if (!TextUtils.isEmpty(item.getPsignOutTime())) {
      outTime =
          MyDateUtil.parseTimeToString(MyDateUtil.stringToDate(item.getPsignOutTime()), "kk:mm");
    }
    if (TextUtils.isEmpty(inTime) && TextUtils.isEmpty(outTime)) {
      vh.tvNameAttendanceSummary.setVisibility(View.GONE);
    } else {
      vh.tvNameAttendanceSummary.setVisibility(View.VISIBLE);
      vh.tvNameAttendanceSummary.setText(String.format("%s ~ %s", inTime, outTime));
    }

    vh.tvSinOutAttendanceSummary.setVisibility(View.GONE);
    vh.mIvPhoto.setVisibility(View.GONE);
    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public SignSummaryListAdapter(Context context,
      List<SignSummaryOriginal.SignSummaryContent> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  @Override public boolean isEmpty() {
    // Auto-generated method stub
    return false;
  }
}
